﻿<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="/base/jquery.min.js"></script>
    <link href="https://cdn.bootcss.com/weui/1.1.2/style/weui.min.css" rel="stylesheet">
    <link href="https://cdn.bootcss.com/jquery-weui/1.2.0/css/jquery-weui.min.css" rel="stylesheet">
    <link href="//at.alicdn.com/t/font_802825_po60p2ysl1f.css" rel="stylesheet" />
</head>

<body>
    <div class="weui-uploader">
        <div class="weui-uploader__hd">
            <p class="weui-uploader__title">图片上传</p>
            <div class="weui-uploader__info">0/2</div>

        </div>
        <div class="">
            <ul class="weui-uploader__files uploader-files" id="list-upload"></ul>
            <div class="weui-uploader__input-box" id="btn-upload">
            </div>
        </div>
    </div>
</body>

</html>


<script>
    $(function () {

        function toTree(data, parent_id) {
            var tree = [];
            var temp;
            for (var i = 0; i < data.length; i++) {
                if (data[i].fatherid == parent_id) {
                    var gtext = "普通会员";
                    switch (data[i].Grade) {
                        case 1:
                            gtext = "普通会员";
                            break;
                        case 2:
                            gtext = "超级用户";
                            break;
                        case 20:
                            gtext = "体验店";
                            break;
                        case 21:
                            gtext = "服务商";
                            break;
                    }
                    var html = '<div class="tree-core-data"><img src="' + data[i].headimgurl + '" />';
                    html += '<p>' + data[i].nickname + '<p>';
                    html += '<p>' + data[i].MemLoginId + '<p>';
                    html += '<span class="badge">' + gtext + '<p>';
                    html += '</div>';
                    data[i]["html"] = html;
                    var obj = data[i];
                    temp = toTree(data, data[i].MemLoginId);
                    if (temp.length > 0) {
                        obj.children = temp;
                    }
                    tree.push(obj);
                }
            }
            return tree;
        }


        var data = [{
                Lv: "0",
                MemLoginId: "10716",
                fatherid: "10024",
                nickname: "纤优纺服饰-钱旭艳",
                headimgurl: "http://thirdwx.qlogo.cn/mmopen/6ic9SHq9YuMvYYYpr4HqOd0C5ZoX92QUdnLnJS7ZajKksXZQibduTFXoADBBic5wDMPyR4apRk8Joib0QcSLwfDyibPkGAiau4GR9A/132",
                Grade: "21"
            },
            {
                Lv: "1",
                MemLoginId: "11138",
                fatherid: "10716",
                nickname: "零丽英",
                headimgurl: "http://thirdwx.qlogo.cn/mmopen/6ic9SHq9YuMvYYYpr4HqOd0C5ZoX92QUdnLnJS7ZajKksXZQibduTFXoADBBic5wDMPyR4apRk8Joib0QcSLwfDyibPkGAiau4GR9A/132",
                Grade: "20"
            },
            {
                Lv: "1",
                MemLoginId: "11281",
                fatherid: "10716",
                nickname: "靖西纤妍&柚言骆骆",
                headimgurl: "http://thirdwx.qlogo.cn/mmopen/6ic9SHq9YuMvYYYpr4HqOd0C5ZoX92QUdnLnJS7ZajKksXZQibduTFXoADBBic5wDMPyR4apRk8Joib0QcSLwfDyibPkGAiau4GR9A/132",
                Grade: "20"
            },
            {
                Lv: "2",
                MemLoginId: "11309",
                fatherid: "11281",
                nickname: "陈晓红",
                headimgurl: "http://thirdwx.qlogo.cn/mmopen/6ic9SHq9YuMvYYYpr4HqOd0C5ZoX92QUdnLnJS7ZajKksXZQibduTFXoADBBic5wDMPyR4apRk8Joib0QcSLwfDyibPkGAiau4GR9A/132",
                Grade: "20"
            },
            {
                Lv: "2",
                MemLoginId: "11178",
                fatherid: "11138",
                nickname: "H3JP黄艺芳",
                headimgurl: "http://thirdwx.qlogo.cn/mmopen/6ic9SHq9YuMvYYYpr4HqOd0C5ZoX92QUdnLnJS7ZajKksXZQibduTFXoADBBic5wDMPyR4apRk8Joib0QcSLwfDyibPkGAiau4GR9A/132",
                Grade: "20"
            }
        ];

        var json = toTree(data, "10024");
        console.log(json);
    })
</script>